// Author: wsfuyibing <682805@qq.com>
// Date: 2025-06-11

package responses

import (
	"server/app/http/models"
	"server/app/kind"
)

// TicketResponse
// 渔票信息.
type TicketResponse struct {
	Id        int64            `label:"渔票ID"`
	ArcadeId  kind.ArcadeId    `label:"钓场ID"`
	State     kind.TicketState `label:"在售状态位"`
	StateFlag string           `label:"状态标识"`
	StateText string           `label:"在售状态值"`
	StateYes  bool             `label:"启用中"`

	Mode      kind.TicketMode `label:"场次模式"`
	ModeText  string          `label:"场次模式名"`
	ModeStart string          `label:"开始日期"`
	ModeEnd   string          `label:"截止日期"`

	Time      kind.TicketTime `label:"作钓时段"`
	TimeText  string          `label:"作钓时段名"`
	TimeStart string          `label:"开始时间"`
	TimeEnd   string          `label:"截止时间"`

	PondId           int64                   `label:"鱼塘ID"`
	Seat             kind.PondSeat           `label:"钓位类型"`
	SeatText         string                  `label:"钓位类型名"`
	SeatStrategy     kind.TicketSeatStrategy `label:"钓位策略"`
	SeatStrategyText string                  `label:"钓位策略名"`

	// 基础项.

	Name     string `label:"名称"`
	Image    string `label:"图片"`
	Datetime string `label:"发布日期"`

	// 销售项.
	Hours        float64      `label:"作钓时长"`
	Price        kind.Balance `label:"售价"`
	Quantity     int          `label:"最大数量"`
	SessionCount int          `label:"全部场次"`
	OrderTotal   int          `label:"下单总数" desc:"含退单"`
	OrderCount   int          `label:"订单数"`
	RefundCount  int          `label:"退单数"`

	Pond *ArcadePondResponse `json:",omitempty"`
}

// With
// 数据绑定.
func (o *TicketResponse) With(m *models.Ticket) *TicketResponse {
	o.Id = m.Id
	o.ArcadeId = m.ArcadeId
	o.State = m.State
	o.StateFlag = m.State.Flag()
	o.StateText = m.State.Text()
	o.StateYes = m.State.IsEnabled()

	o.Mode = m.Mode
	o.ModeText = m.Mode.Text()
	o.ModeStart = m.ModeStart.Time().Format("2006-01-02")
	o.ModeEnd = m.ModeEnd.Time().Format("2006-01-02")

	o.Time = m.Time
	o.TimeText = m.Time.Text()
	o.TimeStart = m.TimeStart
	o.TimeEnd = m.TimeEnd

	o.PondId = m.PondId
	o.Seat = m.Seat
	o.SeatText = m.Seat.Text()
	o.SeatStrategy = m.SeatStrategy
	o.SeatStrategyText = m.SeatStrategy.Text()

	o.Name = m.Name
	o.Image = m.Image
	o.Datetime = m.CreatedAt.Time().Format("2006/01/02")

	o.Hours = m.Hours
	o.Price = m.Price
	o.SessionCount = m.SessionCount
	o.Quantity = m.Quantity
	o.OrderTotal = m.OrderTotal
	o.OrderCount = m.OrderCount
	o.RefundCount = m.RefundCount
	return o
}

// WithPond
// 绑定鱼塘.
func (o *TicketResponse) WithPond(m *models.ArcadePond) *TicketResponse {
	if m != nil {
		o.Pond = (&ArcadePondResponse{}).With(m)
	}
	return o
}
